package com.huawei.fastengine.fastview;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import com.huawei.fastengine.fastview.download.utils.log.FastViewLogUtils;
import com.huawei.fastengine.fastview.startFastappEngine.bean.Options;
import com.huawei.hms.support.api.entity.hwid.HwIDConstant.ACTION;

public class NavigationUtils {
    public static final String ACTIONBAR_LOCK_CUSTOMIZE = "ActionbarLockCustomize";
    public static final String ACTIONBAR_LOCK_STATUS = "ActionbarLockStatus";
    public static final String MAIL_SCHEMA_PREF = "mailto:";
    public static final String SMS_SCHEMA_PREF = "sms";
    private static final String TAG = "NavigationUtils";
    public static final String TEL_SCHEMA_PREF = "tel:";

    public static boolean jumpBySchema(Context context, String str, Options options) {
        Uri parse = Uri.parse(str);
        return TextUtils.isEmpty(parse.getScheme()) ? false : openFile(context, parse, options);
    }

    public static boolean jumpToMail(Context context, String str) {
        String str2 = MAIL_SCHEMA_PREF;
        String substring = str.substring(str2.length());
        try {
            Intent intent = new Intent("android.intent.action.SENDTO", Uri.parse(str2));
            intent.addFlags(268435456);
            intent.putExtra("android.intent.extra.EMAIL", new String[]{substring});
            context.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
            FastViewLogUtils.e(TAG, " jumpToMail error: " + e.toString());
            return false;
        }
    }

    public static boolean jumpToSms(Context context, String str) {
        Intent intent = new Intent("android.intent.action.SENDTO", Uri.parse(str));
        intent.addFlags(268435456);
        try {
            context.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
            FastViewLogUtils.e(TAG, " jumpToSms error: " + e.toString());
            return false;
        }
    }

    public static boolean jumpToTel(Context context, String str) {
        Intent intent = new Intent("android.intent.action.DIAL", Uri.parse(str));
        intent.addFlags(268435456);
        try {
            context.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
            FastViewLogUtils.e(TAG, " jumpToTel error: " + e.toString());
            return false;
        }
    }

    public static boolean openFile(Context context, Uri uri, Options options) {
        try {
            Intent intent = new Intent();
            intent.addFlags(268435456);
            intent.setAction(ACTION.HWID_SCHEME_URL);
            if (uri == null) {
                FastViewLogUtils.w(TAG, "openFile uri is not public");
                return false;
            }
            intent.addFlags(1);
            intent.putExtra(ACTIONBAR_LOCK_CUSTOMIZE, options.getActionbarLockCustomize());
            intent.putExtra(ACTIONBAR_LOCK_STATUS, options.isActionbarLockStatus());
            intent.setData(uri);
            context.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
            FastViewLogUtils.e(TAG, " openFile error: " + e.toString());
            return true;
        }
    }
}
